<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>菜单详情</title>
  <link rel="stylesheet" href="./css/style.css" />
</head>
<style>

</style>

<body>
  <h3 class="big-tit">菜谱详情</h3>
  <div class="container flex-box">
    <div class="left">
      <img src="http://yun.itheima.com/Upload/Images/20220627/62b924298e658.jpg" alt="" />
    </div>
    <div class="right">
      <h3>菜谱名称</h3>
      <p>
        菜谱描述信息菜谱描述信息菜谱描述信息菜谱描述信息菜谱描述信息菜谱描述信息菜谱描述信息菜谱描述信息菜谱描述信息菜谱描述信息菜谱描述信息菜谱描述信息菜谱描述信息菜谱描述信息菜谱描述信息菜谱描述信息菜谱描述信息菜谱描述信息菜谱描述信息菜谱描述信息菜谱描述信息菜谱描述信息菜谱描述信息菜谱描述信息菜谱描述信息菜谱描述信息菜谱描述信息菜谱描述信息菜谱描述信息菜谱描述信息菜谱描述信息
      </p>
      <h5>下面列表是菜谱中美味的菜品哦！</h5>
    </div>
  </div>
  <ul class="list-box">
    <!--
    <li>
      <a href="detail.html">
        <img src="http://yun.itheima.com/Upload/Images/20220627/62b924298e658.jpg" alt="" />
        <h3>菜单名称</h3>
      </a>
    </li> -->
  </ul>
</body>
<script src="./lib/axios.js"></script>

<script>
  // 根路径
  axios.defaults.baseURL = 'http://124.223.14.236:3001/api'

  // 封装获取元素
  const qs = ele => document.querySelector(ele)

  const id = location.search.split('=')[1]

  //获取菜单详情
  async function getMenuInfo() {
    const { data } = await axios.get('/recipe/' + id)
    // alert(JSON.stringify(data))
    if (!data.success) alert(data.msg)
    qs('.left img').src = 'http://124.223.14.236:3001/public/' + data.data.img
    qs('.right h3').innerHTML = data.data.name
    qs('.right p').innerHTML = data.data.description
  }
  getMenuInfo()


  // 渲染美食列表
  async function getFoodList() {
    const { data: { data } } = await axios.get('/recipeInfo/', {
      params: {
        recipe_id: id
      }
    })
    if (data.length) {
      const goodsList = data.map(item => `<li>
      <a href="./detail.html?id=${item.id}">
        <img src="http://124.223.14.236:3001/public/${item.img}" alt="" />
        <h3>${item.title}</h3>
      </a>
    </li>`).join("")
      qs('.list-box').innerHTML = goodsList
    } else {
      qs('body').innerHTML += `<p class="noinfo">没有美食了...</p>`
    }
  }
  getFoodList()

</script>


</html>